#include <iostream>
#include <mutex>

using namespace std;

#define LOGAPP log::getInstance()

class log
{
public:
    static log* getInstance();
    void wirteLog(const string& log);

    // 让编译器自动生成一个析构函数，不需要再定义
    ~log() = delete;
private:
    log() {}
private:
    static log* m_log;
    static mutex m_mutex;
};

log* log::m_log = nullptr;
mutex log::m_mutex;
log* log::getInstance()
{
    if(m_log == nullptr) {          
        lock_guard<mutex> lock(m_mutex);
        if(m_log == nullptr) {
            m_log = new log();
        }
    }
    return m_log;
}

void log::wirteLog(const string& log)
{
    cout << log << "\n";
}


int main(int argc, char* argv[])
{
    log::getInstance()->wirteLog("hello, this is log");
    LOGAPP->wirteLog("this is lanqiao");
    return 0;
}